<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item, index) in list" :key="index">{{item}}</li>
      </ul>

      <p>{{ obj }}</p>

      <button @click="handleClick"></button>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          list: [1, 2, 3, 4, 5],
          obj: {
            a: 3,
            b: 4,
          },
        },
        methods: {
          handleClick() {
            // 响应式会失效
            // 1. 直接通过length改变数组长度
            // 2. 通过索引去改变数组项
            // 3. 在对象里面挂载新属性

            this.list.length = 3;
            // this.list[2] = 30;
            // this.obj.c = 10;

            // this.list = [...this.list];
            this.list = [].concat(this.list);
            // this.obj = { ...this.obj };
            // this.obj = Object.assign({}, this.obj);
          },
        },
      });
    </script>
  </body>
</html>
